package ext.opensource.netty.server.example.scanner;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

@Component
public class HandlerScaner implements BeanPostProcessor {

	@Override
	public Object postProcessBeforeInitialization(final Object bean, final String beanName) throws BeansException {
		//System.err.println("postProcessBeforeInitialization: " + beanName);
		return bean;
	}

	@Override
	public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException {

		final Class<? extends Object> clazz = bean.getClass();

		final Class<?>[] interfaces = clazz.getInterfaces();

		if (interfaces != null && interfaces.length > 0) {
			/*
			 * //扫描类的所有接口父类 for (Class<?> interFace : interfaces) { //判断是否为handler接口类 SocketModule socketModule =
			 * interFace.getAnnotation(SocketModule.class); if (socketModule == null) { continue; } //找出命令方法 Method[]
			 * methods = interFace.getMethods(); if(methods != null && methods.length > 0){ for(Method method :
			 * methods){ SocketCommand socketCommand = method.getAnnotation(SocketCommand.class); if(socketCommand ==
			 * null){ continue; } final short module = socketModule.module(); final short cmd = socketCommand.cmd();
			 * if(InvokerHoler.getInvoker(module, cmd) == null){ InvokerHoler.addInvoker(module, cmd,
			 * Invoker.valueOf(method, bean)); }else{ System.out.println("重复命令:"+"module:"+module +" "+"cmd：" + cmd); }
			 * } } }
			 */
		}
		return bean;
	}

}
